package com.yjhb.android.sbz.mvp.everydaywelfare;

import com.yjhb.android.sbz.entity.EverydayWelfare;
import com.yjhb.android.sbz.http.HttpObserver;
import com.yjhb.android.sbz.http.HttpTool;
import com.yjhb.android.sbz.mvp.ConventionPresenter;

import java.util.List;

/**
 * 创建者 zx
 * 创建时间 2021/1/12 10:46
 */
public class EverydayWelfarePresenter extends ConventionPresenter<EverydayWelfareView> {
    private final String TAG = "EverydayWelfarePresenter";

    @Override
    protected void onDestroy() {

    }

    public EverydayWelfarePresenter(EverydayWelfareView everydayWelfareView) {
        super(everydayWelfareView);
    }

    public void load() {
        if (view != null) {
            view.onWait("正在加载...");
        }
        HttpTool.request(model.getTodayDailyTask(), new HttpObserver<List<EverydayWelfare>>() {
            @Override
            public void onResult(List<EverydayWelfare> data) {
                if (view != null) {
                    view.onLoad(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }

    public void getDailyTaskReward(Integer taskId) {
        if (view != null) {
            view.onWait("正在领取奖励...");
        }
        HttpTool.request(model.getDailyTaskReward(taskId), new HttpObserver<Object>() {
            @Override
            public void onResult(Object data) {
                if (view != null) {
                    view.onSubmit(data);
                }
            }

            @Override
            public void onError(int code, String msg) {
                if (view != null) {
                    view.onFailure(code, msg);
                }
            }
        });
    }
}
